﻿using SinavSistemi.Class;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SinavSistemi
{
    public partial class sonuc : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
          
                SqlConnection sqlcon2 = connection.baglanti;
                SqlCommand sqlcmd2 = new SqlCommand("select * from kullanicilar where userID=@uid", sqlcon2);
                sqlcmd2.Parameters.AddWithValue("@uid",Session["userID"]);

                sqlcon2.Open();
                SqlDataReader sdr = sqlcmd2.ExecuteReader();
                while (sdr.Read())
                {
                    lblAdSoyad.Text = sdr["adsoyad"].ToString();
                    lblFirma.Text = sdr["firmaID"].ToString();
                    lblEmail.Text = sdr["email"].ToString();

                }

                sqlcon2.Close();

        


            decimal ss = Convert.ToInt32(Session["sorusayisi"]);
            SqlConnection sqlcon = connection.baglanti;
            SqlCommand sqlcmd = new SqlCommand("select COUNT(*) as dogrucevap from cevaplar as c inner join uygulanamalar as u on u.sinavID=c.sinavID  inner join sorular as s on s.soruID=c.soruID where u.userID=@userID and c.cevap=s.cevap ", sqlcon);
            sqlcmd.Parameters.AddWithValue("@userID",Session["userID"]);

            

            sqlcon.Open();
            decimal dogrusayi = Convert.ToDecimal(sqlcmd.ExecuteScalar());
            sqlcon.Close();

            decimal puan = (dogrusayi /ss )*100;
            SqlCommand sqlcmd3 = new SqlCommand("update uygulanamalar set puan=@puan where userID=@userID ",sqlcon);
            sqlcmd3.Parameters.AddWithValue("@puan",puan);
            sqlcmd3.Parameters.AddWithValue("@userID",Session["userID"]);
            sqlcon.Open();
            sqlcmd3.ExecuteNonQuery();
            sqlcon.Close();
          
            Label1.Text ="Puanininz (100 üzerinden) :"+ puan.ToString();
        }
    }
}